/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package calysoft;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author Isiredhy
 */
public class Conexion {
    String driver = "org.postgresql.Driver";
    String url = "jdbc:postgresql://localhost:4040/prueba";
    String user = "";
    String pwd = "";
    
    public ResultSet Listar(String Cad) {
        try {
            Class.forName(driver).newInstance();
            Connection cn = DriverManager.getConnection(url, user, pwd);
            PreparedStatement ps = cn.prepareStatement(Cad);
            ResultSet tbl = ps.executeQuery();
            return tbl;
        } catch (Exception e) {
            javax.swing.JOptionPane.showMessageDialog(null, e.getMessage());
            return null;
        }
    }

    public String Ejecutar(String Cad) {
        try {
            Class.forName(driver).newInstance();
            Connection cn = DriverManager.getConnection(url, user, pwd);
            PreparedStatement ps = cn.prepareStatement(Cad);
            int r = ps.executeUpdate();
            return "Se afectaron " + r + " filas";
        } catch (Exception e) {
            javax.swing.JOptionPane.showMessageDialog(null, e.getMessage());
            return "Error " + e.getMessage();
        }
    }
    
}
